import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';

import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/of";

import {Condition, FilterResponse} from '../../../model/pages/client/client-filter/client-filter.model';
import * as moment from "moment";

@Injectable()
export class ClientFilterListProvider {
    private url = '/party/v1/filterClient';

    constructor(public http: HttpClient) {

    }

    convertParamsTimeToString<T>(tar,propertyArr:Array<string>):T{
        propertyArr.map((v1)=>{
            if(tar[v1]){
                tar[v1] = moment(tar[v1]*1000).format('YYYY-MM-DD HH:mm:ss');
            }
        });
        console.log(tar);
        return tar;
    }

    // 筛选请求
    getClientFilter(condition: Condition, notLoading): Observable<any> {
        const url=`/party/v1/filterClient?not-loading=${notLoading}`;
        //this.convertParamsTimeToString(condition,['orphanPolicyDateFrom' , 'orphanPolicyDateTo' ,'lastSignDateFrom' , 'lastSignDateTo' , 'claimDateFrom' , 'claimDateTo']);
        return this.http.post(url, condition)
    }

}
